/**
 * @Title：PageInfo.java
 * @Package com.pyaoyue.cust.common.vo
 * @Description:TODO(用一句话描述该文件做什么)
 * @author lbs
 * @version V1.0
 */
package com.muyan.sys.common.core.domain.model;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.List;

/**
 * @Description: 分页对象
 * @author lbs
 * @version V1.0
 *
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Tag(name = "分页数据")
public class PagedInfo<T> implements Serializable {

	private static final long serialVersionUID = 1581339183912151467L;
	
	//当前页
	@Schema(description = "当前页")
    private long pageNum;
    //每页的数量
	@Schema(description = "每页的数量")
    private long pageSize;
    //总页数
	@Schema(description = "总页数")
    private long pages;
    //总记录数
	@Schema(description = "总记录数")
    private long total;
    //是否有下一页
	@Schema(description = "是否有下一页")
    private boolean hasNextPage = false;
    //数据列表
	@Schema(description = "数据列表")
    private List<T> list;
	public PagedInfo() {
		this.pageNum = 1;
		this.pageSize = 20;
		this.pages =0;
		this.total = 0;
		this.hasNextPage = false;
		this.list =null;
	}
    public PagedInfo(IPage<T> pageInfo) {
    	this.pageNum = pageInfo.getPages();
    	this.pageSize = pageInfo.getSize();
    	this.pages = this.total / this.pageSize + (total % this.pageSize == 0L ? 0 : 1);
    	this.total = pageInfo.getTotal();
		this.hasNextPage = this.pageNum < this.pages;
    	this.list = pageInfo.getRecords();
    }
	public PagedInfo(List<T> list) {
		this.pageNum =1;
		this.pageSize = list.size();
		this.pages = 1;
		this.total = list.size();
		this.hasNextPage =false;
		this.list = list;
	}
}
